const  http =require('http')
const fs=require('fs')
const {join}=require('path')

//网站根目录
const rootpath=join(__dirname,'www')
http.createServer((req,res)=>{
    if(req.url!='./favicon.ico'){
        let pathname=req.url==='/' ? './index.html':req.url
        let filepath=join(rootpath,pathname)
        let errpath=join(rootpath,"./404.html")
        if(fs.existsSync(filepath)){
            res.end(fs.readFileSync(filepath))
           
        }else{
            res.statusCode=404
            res.end(fs.readFileSync(errpath))
        }
    }
}).listen(3000,'0.0.0.0')